//
//  ViewController.m
//  UI05_Homework---
//
//  Created by MacBook Air on 16/5/9.
//  Copyright © 2016年 MacBook Air. All rights reserved.
//

#import "ViewController.h"
#import "SimpleSlider.h"
#import "SimpleSwitch.h"
#import "SimplePageControl.h"
#import "SimpleSegmentControl.h"
#define COLORAUTO [UIColor colorWithRed:arc4random()%260/225.0 green:arc4random()%260/225.0 blue:arc4random()%260/225.0 alpha:1.0]
@interface ViewController ()
@property(nonatomic,retain)SimpleSlider *sli1;
@property(nonatomic,retain)SimpleSlider *sli2;
@property(nonatomic,retain)SimpleSlider *sli3;
@property(nonatomic,retain)SimpleSlider *sli4;
@end

@implementation ViewController
-(void)dealloc{
    [_sli1 release];
    [_sli2 release];
    [_sli3 release];
    [_sli4 release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    [self createSlider];
    [self createSegment];
    
}
-(void)createSlider{
    self.sli1=[[SimpleSlider alloc]initWithFrame:CGRectMake((self.view.frame.size.width-200)/2,self.view.frame.size.height*0.1, 200, 50)];
    [self.view addSubview:self.sli1];
    [self.sli1 addTarget:self action:@selector(handleOfChange:) forControlEvents:UIControlEventValueChanged];
    self.sli1.minimumTrackTintColor=[UIColor redColor];
    self.sli1.maximumTrackTintColor=[UIColor redColor];
    
    self.sli2=[[SimpleSlider alloc]initWithFrame:CGRectMake((self.view.frame.size.width-200)/2, self.view.frame.size.height*0.3, 200, 50)];
    [self.view addSubview:self.sli2];
    [self.sli2 addTarget:self action:@selector(handleOfChange:) forControlEvents:UIControlEventValueChanged];
    self.sli2.minimumTrackTintColor=[UIColor yellowColor];
    self.sli2.maximumTrackTintColor=[UIColor yellowColor];

    self.sli3=[[SimpleSlider alloc]initWithFrame:CGRectMake((self.view.frame.size.width-200)/2, self.view.frame.size.height*0.5, 200, 50)];
    [self.view addSubview:self.sli3];
    [self.sli3 addTarget:self action:@selector(handleOfChange:) forControlEvents:UIControlEventValueChanged];
    self.sli3.minimumTrackTintColor=[UIColor blueColor];
    self.sli3.maximumTrackTintColor=[UIColor blueColor];
    
    self.sli4=[[SimpleSlider alloc]initWithFrame:CGRectMake((self.view.frame.size.width-200)/2, self.view.frame.size.height*0.7, 200, 50)];
    [self.view addSubview:self.sli4];
    [self.sli4 addTarget:self action:@selector(handleOfChange:) forControlEvents:UIControlEventValueChanged];
    
}
-(void)handleOfChange:(SimpleSlider *)slider{
    self.view.backgroundColor=[UIColor colorWithRed:self.sli1.value green:self.sli2.value blue:self.sli3.value alpha:self.sli4.value];
}
-(void)createSegment{
    SimpleSegmentControl *segment=[[SimpleSegmentControl alloc ]initWithItems:@[@"登录",@"注册",@"忘记密码"]];
    [self.view addSubview:segment];
    segment.frame=CGRectMake((self.view.frame.size.width-250)/2, 600, 250, 100) ;
    segment.selectedSegmentIndex=0;
    segment.backgroundColor=COLORAUTO;
    [segment addTarget:self action:@selector(handleOfColor:) forControlEvents:UIControlEventValueChanged];
    [segment release];
}
-(void)handleOfColor:(SimpleSegmentControl *)segment{
    switch (segment.selectedSegmentIndex) {
        case 0:
            self.view.backgroundColor=COLORAUTO;
            break;
            case 1:
            self.view.backgroundColor=COLORAUTO;
            break;
            case 2:
            self.view.backgroundColor=COLORAUTO;
            break;
            
        default:
            break;
    }
}
@end
